package com.ct.controller.shipping;

import com.ct.application.shipping.model.po.LiuChengDingYiSavePO;
import com.ct.application.shipping.model.po.LiuChengDingYiSearchPO;
import com.ct.application.shipping.model.vo.LiuChengVO;
import com.ct.application.shipping.model.vo.LiuChengXiangQingVO;
import com.ct.application.shipping.service.LiuChengDingYiService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 流程定义配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = " 流程定义",path="/api/v1/liuchengdingyi",code = "lcdy1000",sorted = 50)
public class LiuChengDingYiController extends BaseController {

    @Resource
    private LiuChengDingYiService liuChengDingYiService;


    /**
     * 查询流程定义数据
     */
    @PostMapping("/liuchengdingyi/list")
    @PermissionApi(title = "查询流程定义数据",path="/api/v1/liuchengdingyi/list",code = "lcdy1001",sorted = 1)
    public LiuChengVO findLiuChengDingYi(@Validated @RequestBody LiuChengDingYiSearchPO searchPO) {
        return liuChengDingYiService.findLiuChengDingYi(searchPO);
    }

    /**
     * 保存和更新
     */
    @PostMapping("/liuchengdingyi/saveupdate")
    @ApiLog("流程定义保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "流程定义保存和更新",path="/api/v1/liuchengdingyi/saveupdate",code = "lcdy1002",sorted = 2)
    public Boolean saveUpdateLiuChengDingYi(@Validated @RequestBody LiuChengDingYiSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return liuChengDingYiService.updateLiucChengDingyi(savePO);
        }else {
            return liuChengDingYiService.saveLiucChengDingyi(savePO);
        }
    }

    /**
     * 根据id查询流程定义信息
     */
    @PostMapping("/liuchengdingyi/get/{id}")
    @PermissionApi(title = "根据id查询流程定义信息",path="/api/v1/liuchengdingyi/get/{id}",code = "lcdy1003",sorted = 3)
    public LiuChengXiangQingVO getLiuChengDingYiById(@PathVariable("id") Long id) {
        return liuChengDingYiService.getLiucChengDingyi(id);
    }


    /**
     * 根据id删除
     */
    @PostMapping("/liuchengdingyi/del/{id}")
    @ApiLog("根据id删除定义信息")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除定义信息",path="/api/v1/liuchengdingyi/del/{id}",code = "lcdy1004",sorted = 4)
    public Boolean delLiuChengDingYiById(@PathVariable("id") Long id) {
        return liuChengDingYiService.delLiucChengDingyi(id);
    }
}
